<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>
BaseViewmodel class
</TITLE>

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../resources/stylesheet.css" TITLE="Style">
</HEAD>

<BODY BGCOLOR="white">


<!-- ========= START OF TOP NAVBAR ======= -->

<table border="0" width="100%">
<tr>
<td width="50%">
<p align="left">
<a href="http://mvvmbasics.mobilemotion.eu/" target="_blank" title="MVVMbasics Homepage"><img src="../../resources/logo_mvvmbasics.png" alt="MVVMbasics Logo" border="0"></a>
</p>
</td>
<td width="50%">
<p align="right">
<a href="http://www.mobilemotion.eu/" target="_blank" title="mobilemotion.eu Homepage"><img src="../../resources/logo_mobilemotion.png" alt="mobilemotion.eu Logo" border="0"></a>
</p>
</td>
</tr>
</table>

<HR>

<p><a href="../../index.htm" title="MVVMbasics Class Reference Homepage">Back to Class Reference home page</a></p>

<!-- ========= END OF TOP NAVBAR ========= -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">MVVMbasics.Viewmodels</FONT>
<BR>
Class BaseViewmodel
</H2>

<CODE>
<a href="../Models/BaseModel.htm" title="BaseModel">MVVMbasics.Models.BaseModel</a>
<br>
&nbsp;&nbsp;<IMG SRC="../../resources/inherit.gif" ALT="extended by "><B>MVVMbasics.Viewmodels.BaseViewmodel</B>
<br>&nbsp;
</CODE>
<HR>
<CODE>
&nbsp;<br>
public abstract class <B>BaseViewmodel</B> : <a href="../Models/BaseModel.htm" title="BaseModel">BaseModel</a>
</CODE>

<P>
Base viewmodel class all actual viewmodels can be derived from.
</P>

<hr>

<!-- ======== PROPERTY SUMMARY ======== -->

<A NAME="property_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Property Summary</B></FONT></TH>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD>
<CODE>public <a href="../Services/ViewState.htm" title="ViewState">ViewState</a> <B>ViewState</B> { get; private set; }</CODE>
<BR>
<span class="Indented">Flag that indicates whether the View which is registered to this Viewmodel is active (shown on the screen) or not. Can be used to decide whether a message box shall be shown or not, for example.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD>
<CODE><S>public <a href="../Helpers/ServiceLocator.htm" title="ServiceLocator">ServiceLocator</a> <B>ServiceLocator</B> { get; set; }</S></CODE>
<BR>
<span class="Indented">ServiceLocator to be used to retrieve service instances during Viewmodel logic. Is set by the View when instantiating the Viewmodel, only if it was defined in the <code>BaseApplication</code>.<br>
Should be used instead of directly referencing <code>Application.Current.ServiceLocator</code>, since the Application might not in all cases be accesible (e.g., in multi-platform Apps the Viewmodel might be located within a Portable Class Library that can not access the <code>Application</code> classes.</span>
<BR>
<span class="Obsolete">Deprecated. Inject ServiceLocator into Viewmodel by using parameterized constructor <code>Viewmodel(ServiceLocator s)</code> instead.</span>
</TD>
</TR>
</TABLE>
&nbsp;

<!-- ======== CONSTRUCTOR SUMMARY ======== -->

<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>public&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#BaseViewmodel()">BaseViewmodel</a></B>()</CODE>
<BR>
<span class="Indented">Tries to set the <code>CommandAutobinding</code> flag depending on whether an <a href="../Attributes/MvvmCommandAutobinding.htm" title="MvvmCommandAutobinding">MvvmCommandAutobinding</a> attribute is registered, and automatically binds Commands to methods if applicable.</span>
</TD>
</TR>
</TABLE>
&nbsp;

<!-- ======== METHOD SUMMARY ======== -->

<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>virtual void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><S><B><a href="#OnServiceLocatorAvailable()">OnServiceLocatorAvailable</a></B>()</S></CODE>
<BR>
<span class="Indented">Method that is called when the App's <a href="../Helpers/ServiceLocator.htm" title="ServiceLocator">ServiceLocator</a> is set for the first time. Usually this happens shortly after the constructor.</span>
<BR>
<span class="Obsolete">Deprecated. Inject ServiceLocator into Viewmodel by using parameterized constructor <code>Viewmodel(ServiceLocator s)</code> instead.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>virtual void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#OnNavigatedTo(ParameterList,ParameterList,ViewState)">OnNavigatedTo</a></B>(<a href="../Services/ParameterList.htm" title="ParameterList">ParameterList</a> uriParameters, <a href="../Services/ParameterList.htm" title="ParameterList">ParameterList</a> parameters, <a href="../Services/ViewState.htm" title="ViewState">ViewState</a> viewState)</CODE>
<BR>
<span class="Indented">Method that is called when navigating to a page / window.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>virtual void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#CancelNavigatingFrom(ViewState)">CancelNavigatingFrom</a></B>(<a href="../Services/ViewState.htm" title="ViewState">ViewState</a> viewState)</CODE>
<BR>
<span class="Indented">Method that is called when the page / window is about to be closed, in order to return back to  previously shown page / window.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>virtual void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#OnNavigatedFrom(ViewState)">OnNavigatedFrom</a></B>(<a href="../Services/ViewState.htm" title="ViewState">ViewState</a> viewState)</CODE>
<BR>
<span class="Indented">Method that is called when a page / window is closed.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B><a href="#RunOnMainThread(Action)">RunOnMainThread</a></B>(<A HREF="http://msdn.microsoft.com/en-us/library/system.action%28v=vs.110%29.aspx" target="_blank" title="System.Action">Action</A> action)</CODE>
<BR>
<span class="Indented">Helper method that checks if some actions needs to be invoked on the main thread, and calls the dispatcher to do so.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected void&nbsp;</CODE></FONT></TD>
<TD>
<A NAME="Set(T)(field,value,propertyName)"><!-- --></A>
<CODE><B>Set&lt;T&gt;</B>(ref T field, T value, [<a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute%28v=vs.110%29.aspx" target="_blank" title="CallerMemberNameAttribute Class">CallerMemberName</a>] string propertyName = "")</CODE>
<BR>
<span class="Indented">Setter method that sets the private member field and fires the <code>PropertyChanged</code> event using the Dispatcher.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B>Set&lt;T&gt;</B>(<a href="http://msdn.microsoft.com/en-us/library/bb534960%28v=vs.110%29.aspx" target="_blank" title="System.Func<TResult>">Func</a>&lt;bool&gt;&gt; before, ref T field, T value, [<a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute%28v=vs.110%29.aspx" target="_blank" title="CallerMemberNameAttribute Class">CallerMemberName</a>] string propertyName = "")</CODE>
<BR>
<span class="Indented">Setter method that sets the private member field, fires the <code>PropertyChanged</code> event using the Dispatcher and calls a specified method to decide whether to continue updating the member field.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected void&nbsp;</CODE></FONT></TD>
<TD>
<A NAME="Set(T)(field,value,after,propertyName)"><!-- --></A>
<CODE><B>Set&lt;T&gt;</B>(ref T field, T value, <A HREF="http://msdn.microsoft.com/en-us/library/system.action%28v=vs.110%29.aspx" target="_blank" title="System.Action">Action</A> after, [<a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute%28v=vs.110%29.aspx" target="_blank" title="CallerMemberNameAttribute Class">CallerMemberName</a>] string propertyName = "")</CODE>
<BR>
<span class="Indented">Setter method that sets the private member field, fires the <code>PropertyChanged</code> event using the Dispatcher and calls a specified method after updating the member field.</span>
</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected void&nbsp;</CODE></FONT></TD>
<TD>
<CODE><B>Set&lt;T&gt;</B>(<a href="http://msdn.microsoft.com/en-us/library/bb534960%28v=vs.110%29.aspx" target="_blank" title="System.Func<TResult>">Func</a>&lt;bool&gt;&gt; before, ref T field, T value, <A HREF="http://msdn.microsoft.com/en-us/library/system.action%28v=vs.110%29.aspx" target="_blank" title="System.Action">Action</A> after, [<a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute%28v=vs.110%29.aspx" target="_blank" title="CallerMemberNameAttribute Class">CallerMemberName</a>] string propertyName = "")</CODE>
<BR>
<span class="Indented">Setter method that sets the private member field, fires the <code>PropertyChanged</code> event using the Dispatcher and calls two specified methods: One before updating the member field to decide whether to continue, one after updating the member field.</span>
</TD>
</TR>
</TABLE>
&nbsp;

<!-- ========= CONSTRUCTOR DETAIL ======== -->

<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>

<A NAME="BaseViewmodel()"><!-- --></A><H3>
BaseViewmodel</H3>
<CODE>public <B>BaseViewmodel</B>()</CODE>
<p class="Indented">Tries to set the <code>CommandAutobinding</code> flag depending on whether an <a href="../Attributes/MvvmCommandAutobinding.htm" title="MvvmCommandAutobinding">MvvmCommandAutobinding</a> attribute is registered, and automatically binds Commands to methods if applicable.</p>

<!-- ========= METHOD DETAIL ======== -->

<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>

<A NAME="OnServiceLocatorAvailable()"><!-- --></A><H3>
OnServiceLocatorAvailable</H3>
<CODE><S>public virtual void <B>OnServiceLocatorAvailable</B>()</S></CODE>
<p class="Indented">Method that is called when the App's <a href="../Helpers/ServiceLocator.htm" title="ServiceLocator">ServiceLocator</a> is set for the first time. Usually this happens shortly after the constructor.<br>
Subclasses can override this method to be notified when the <code>ServiceLocator</code> is available, and then do all the tasks that would occur in the constructor but are dependent on the <code>ServiceLocator</code>.</p>
<p class="Indented Obsolete">Deprecated. Inject ServiceLocator into Viewmodel by using parameterized constructor <code>Viewmodel(ServiceLocator s)</code> instead.</p>

<HR>

<A NAME="OnNavigatedTo(ParameterList,ParameterList,ViewState)"><!-- --></A><H3>
OnNavigatedTo</H3>
<CODE>public virtual void <B>OnServiceLocatorAvailable</B>(<a href="../Services/ParameterList.htm" title="ParameterList">ParameterList</a> uriParameters, <a href="../Services/ParameterList.htm" title="ParameterList">ParameterList</a> parameters, <a href="../Services/ViewState.htm" title="ViewState">ViewState</a> viewState)</CODE>
<p class="Indented">Method that is called when navigating to a page / window.<br>
Subclasses can override this method to be notified when the page / window they represent is loaded and shown on the screen. In addition, all parameters that were passed to the page / window can be easily retrieved and processed inside this method.</p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>parameters</CODE> - List of parameters that were passed from the calling page / window.<br>
<CODE>uriParameters</CODE> - List of parameters that were contained within the URI used to navigate to the current page / window.<br>
<CODE>viewState</CODE> - Indicates the lifecycle state the View is about to reach.<br>
</p>
</div>

<HR>

<A NAME="CancelNavigatingFrom(ViewState)"><!-- --></A><H3>
CancelNavigatingFrom</H3>
<CODE>public virtual void <B>CancelNavigatingFrom</B>(<a href="../Services/ViewState.htm" title="ViewState">ViewState</a> viewState)</CODE>
<p class="Indented">Method that is called when the page / window is about to be closed, in order to return back to  previously shown page / window.<br>
Subclasses can override this method and return TRUE in order to cancel the closing and the navigation process.</p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>viewState</CODE> - Indicates the lifecycle state the View is about to reach.<br>
</p>
</div>

<HR>

<A NAME="OnNavigatedFrom(ViewState)"><!-- --></A><H3>
OnNavigatedFrom</H3>
<CODE>public virtual void <B>OnNavigatedFrom</B>(<a href="../Services/ViewState.htm" title="ViewState">ViewState</a> viewState)</CODE>
<p class="Indented">Method that is called when a page / window is closed.<br>
Subclasses can override this method to be notified when the page / window they represent is closed.<p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>viewState</CODE> - Indicates the lifecycle state the View is about to reach.<br>
</p>
</div>

<HR>

<A NAME="RunOnMainThread(Action)"><!-- --></A><H3>
RunOnMainThread</H3>
<CODE>protected void <B>RunOnMainThread</B>(<A HREF="http://msdn.microsoft.com/en-us/library/system.action%28v=vs.110%29.aspx" target="_blank" title="System.Action">Action</A> action)</CODE>
<p class="Indented">Helper method that checks if some actions needs to be invoked on the main thread, and calls the dispatcher to do so.<p>

<div class="Indented">
<B>Parameters:</B>
<p class="Indented">
<CODE>action</CODE> - Action to be invoked using the dispatcher if necessary.<br>
</p>
</div>

<!-- ========= END OF CLASS DATA ========= -->
<HR>

</body>
</HTML>